package com.yitiao.data_algorithms.leetcode.editor.cn;

import com.yitiao.data_algorithms.leetcode.editor.cn.base.TreeNode;

class FlipEquivalentBinaryTrees {
    // 2023-05-08 18:27:00
    public static void main(String[] args) {
        Solution solution = new FlipEquivalentBinaryTrees().new Solution();
    }

    //leetcode submit region begin(Prohibit modification and deletion)

    /**
     * Definition for a binary tree node.
     * public class TreeNode {
     * int val;
     * TreeNode left;
     * TreeNode right;
     * TreeNode() {}
     * TreeNode(int val) { this.val = val; }
     * TreeNode(int val, TreeNode left, TreeNode right) {
     * this.val = val;
     * this.left = left;
     * this.right = right;
     * }
     * }
     */
    class Solution {
        public boolean flipEquiv(TreeNode root1, TreeNode root2) {
            // 只要有一个节点为空，两个就必须都为null裁返回true
            if (root1 == null || root2 == null) {
                return root1 == null && root2 == null;
            }
            return root1.val == root2.val && (
                    (flipEquiv(root1.left, root2.left) && flipEquiv(root1.right, root2.right)) ||
                            (flipEquiv(root1.left, root2.right) && flipEquiv(root1.right, root2.left))
            );

        }

    }
//leetcode submit region end(Prohibit modification and deletion)

}